/**
 *ZHU framework. Copyright 2007-, all rights reserved.
 *
 * $Id$
 * $Revision$
 * $Date$
 * $Author$
 */
package daily.service;

import java.util.*;

import javax.ejb.*;

import org.primefaces.model.*;

import zhu.framework.service.*;
import daily.entity.*;

/**
 * @author xiaopengzhu
 * 
 */
@Stateless
public class FilesServiceImpl extends AbstractPersistenceOperationService {

	public void saveFile(final ServiceRequestContext serviceRequestContext, final UploadedFile file) {
		final Files fileTable = new Files();
		fileTable.setByteFile(file.getContents());
		fileTable.setContentTyp(file.getContentType());
		fileTable.setFilename(file.getFileName());
		fileTable.setUploadStaff(serviceRequestContext.getLoginStaff());
		doCreateEntity(fileTable, Files.class);
	}

	public List<Files> getFileList() {
		final FilesLifecycle lifecycle = getLifecycleFactory().getLifecycle(FilesLifecycle.class);
		return lifecycle.findAll();
	}

	public void deleteFile(final Files selectedFile) {
		doRemoveEntity(selectedFile, Files.class);
	}

	public byte[] getByteFile(final Files selectedFile) {
		final FilesLifecycle lifecycle = getLifecycleFactory().getLifecycle(FilesLifecycle.class);
		return lifecycle.findById(selectedFile.getEntityId()).getByteFile();
	}

}
